package service;

import bean.LoginInformation;
import bean.User;
import dao.UserDao;
import factory.UserDaoFactory;

import java.util.List;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 2:51 下午 2021/5/27
 */
public class UserService {
    private UserDao userDao;

    public UserService() {
        this.userDao = UserDaoFactory.getUserDao();
    }

    //
    public boolean loginService(LoginInformation loginInformation) {
        List<LoginInformation> list = userDao.findManager();
        for (LoginInformation l : list) {
            if (l.getUserName().equals(loginInformation.getUserName()) && l.getPassWord().equals(loginInformation.getPassWord())) {
                return true;
            }
        }
        return false;
    }

    public List getAllUserService(int page) {
        return userDao.getAllUser(page);
    }

    public boolean addUserService(User user) {
        int isSuccess = userDao.addUser(user);
        if (isSuccess == 1) {
            return true;
        }
        return false;
    }

    public boolean deleteUserService(int sno) {
        int isSuccess = userDao.deleteUser(sno);
        if (isSuccess == 1) {
            return true;
        }
        return false;
    }

    public List<User> getUserBySno(int sno){
        return userDao.selectUserBySno(sno);
    }

    public boolean updateUserService(User user){
        int isSuccess=userDao.updateUser(user);
        if(isSuccess==1){
            return true;
        }
        return false;
    }
}
